package com.whj.wkpt.service;

import com.whj.wkpt.entity.TaskReview;
import com.whj.wkpt.mapper.TaskReviewMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class TaskReviewService {

    @Autowired
    private TaskReviewMapper taskReviewMapper;

    public TaskReview createReview(TaskReview taskReview) {
        taskReview.setCreateTime(LocalDateTime.now());
        taskReview.setUpdateTime(LocalDateTime.now());
        taskReview.setReviewTime(LocalDateTime.now());
        taskReviewMapper.insert(taskReview);
        return taskReview;
    }

    public TaskReview updateReview(TaskReview taskReview) {
        taskReview.setUpdateTime(LocalDateTime.now());
        taskReviewMapper.update(taskReview);
        return taskReview;
    }

    public void deleteReview(Long reviewId) {
        taskReviewMapper.deleteById(reviewId);
    }

    public TaskReview findById(Long reviewId) {
        return taskReviewMapper.findById(reviewId);
    }

    public List<TaskReview> findAll() {
        return taskReviewMapper.findAll();
    }

    public List<TaskReview> findByTaskId(Long taskId) {
        return taskReviewMapper.findByTaskId(taskId);
    }
}